#include "stdafx.h"

#include "parser_internal.h"
#include "parser_state.h"
#include "parser_errors.h"

#include "ast.h"
#include "ast_modules.h"

namespace funpl
{

namespace parser
{

/// Constructs an abstract syntax tree from the given source code.
void construct_ast(ast::tree &tree, const char *source, debug::error_info *pErrors)
{
	tree.clear();

	parser_state state(&tree, source, pErrors);

	try
	{
		// One module per compilation unit
		tree.root = parse_module(state, nullptr);
	}
	// Fail silently, error information has been collected
	catch(const parse_exception&) { }
}

} // namespace

} // namespace